# 练习1： 拿“3testDownBox - 弹出框.html”  文件练习3种弹出框的处理
# from selenium import webdriver
# from time import sleep
# driver = webdriver.Firefox()
# driver.get('file:///F:/chenyongxing/%E8%AF%BE%E5%A0%82%E7%AC%94%E8%AE%B0/3testDownBox%20-%20%E5%BC%B9%E5%87%BA%E6%A1%86.html')
# sleep(2)
# driver.find_element("id","alert").click()
# sleep(2)
# ele = driver.switch_to.alert
# print(ele.text)
# sleep(2)
# ele.accept()
# sleep(2)
# driver.find_element("id","confirm").click()
# sleep(2)
# ele1 = driver.switch_to.alert
# print(ele1.text)
# sleep(2)
# ele1.dismiss()
# sleep(2)
# driver.find_element("id","prompt").click()
# sleep(2)
# driver.switch_to.alert.send_keys("人眼加")
# ele2 = driver.switch_to.alert
# ele2.accept()
# sleep(2)

# 练习2： 拿 “4select - 下拉框.html”文件练习下拉框的11种操作方法
# from selenium import webdriver
# from time import sleep
#
# from selenium.webdriver.support.select import Select
#
# driver = webdriver.Firefox()
# driver.get('file:///F:/chenyongxing/%E8%AF%BE%E5%A0%82%E7%AC%94%E8%AE%B0/4select%20-%20%E4%B8%8B%E6%8B%89%E6%A1%86.html')
# sleep(1)
# ele = driver.find_element("id","nr")
# ele.click()
# select_obj = Select(driver.find_element("id","nr"))
# sleep(1)
# ele.click()
# select_obj.select_by_value("10")
# sleep(1)
# ele.click()
# select_obj.select_by_index(1)
# sleep(1)
# ele.click()
# select_obj.select_by_visible_text("显示50条")
# sleep(1)
# all_obj = len(select_obj.options)
# for i in range(all_obj):
#     ele.click()
#     select_obj.select_by_index(i)
#     sleep(1)
# ele = driver.find_element("id","moreselAge")
# select_obj = Select(ele)
# select_obj.select_by_value("1")
# select_obj.select_by_value("2")
# print(select_obj.all_selected_options)      #返回所有被选中的选项，返回列表
# print(select_obj.is_multiple)               #判断是否是多选下拉框
# select_obj.deselect_all()                   #取消全部选项
# select_obj.deselect_by_index(0)             #通过索引取消
# select_obj.deselect_by_value("1")           #通过值取消
# select_obj.deselect_by_visible_text("唱歌")  #通过文本信息取消    #选择第一个被选中的选项
# 练习3：oa系统循环点击“已办事项”里面的下拉框操作
from selenium import webdriver
from time import sleep

from selenium.webdriver.support.select import Select

# webdriver = webdriver.Chrome()
driver = webdriver.Firefox()
# driver.get('https://www.baidu.com')
# driver.get('https://mail.qq.com/')
driver.get('http://127.0.0.1:8080/oa/login.jsp')
sleep(1)
driver.find_element("name","loginId").send_keys("admin")
sleep(1)
driver.find_element("name","password").send_keys("sys123456")
sleep(1)
driver.find_element("id","button_submit").click()
sleep(1)
driver.find_element("link text","已办事项").click()
sleep(1)
ele = driver.find_element("id","iframe_main")
driver.switch_to.frame(ele)
ele10 = driver.find_element("name","listframe")
driver.switch_to.frame(ele10)
sleep(1)
ele1 = driver.find_element("name","searchCondition")
ele1.click()
select_obj = Select(ele1)
all_obj = len(select_obj.options)
for i in range(all_obj):
    ele1.click()
    select_obj.select_by_index(i)
    if i == 6 or i == 7:
        ele2 = ""
        if i == 6:
            ele2 = driver.find_element("id", "secretLevel")
        if i == 7:
            ele2 = driver.find_element("id", "urgentLevel")
        ele2.click()
        select_obj1 = Select(ele2)
        all_obj1 = len(select_obj1.options)
        for j in range(all_obj1):
            ele2.click()
            select_obj1.select_by_index(j)
            sleep(1)
sleep(1)
